<?php


namespace app\api\model;


use think\Db;
use think\Model;

class Pay extends Model
{

    // 表名
    protected $name = 'express_pay';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    const PAY_TYPE = [
        0=>'余额支付',
        1=>'微信支付',
        2=>'支付宝',
        3=>'线下支付'
    ];

    const PAY_STATE = [
        0=>'未支付',
        1=>'已支付',
        2=>'已退款',
        3=>'待审核',
        4=>'审核失败'
    ];

    public function settle($payamount){
        Db::startTrans();
        // 更新订单状态
        $this->save([
            'pay_state' => '1',
            'actual_payment' => $payamount,
            'paytime' => time(),
        ]);
//        $orderList = [];
//        $orders = model('app\api\model\Order')
//            ->with(['goods'])
//            ->where('id','in',$this->order_ids)
//            ->where('status','waitingpay')
//            ->select();
//        foreach ($orders as $order){
//            $orderList[] = [
//                'id' => $order['id'],
//                'status' => 'successpay',
//            ];
//        }
//        model('app\api\model\Order')->saveAll($orderList);


        Db::name('express_package')->where('id','in',$this->order_ids)->update([
            'status' => 'successpay',
        ]);

        Db::commit();
        return true;
    }
}